package com.ruoyi.team.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.team.domain.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.team.mapper.CustomerVisitMapper;
import com.ruoyi.team.domain.CustomerVisit;
import com.ruoyi.team.service.ICustomerVisitService;

/**
 * 拜访信息Service业务层处理
 *
 * @author Judy
 * @date 2022-11-27
 */
@Service
public class CustomerVisitServiceImpl extends ServiceImpl<CustomerVisitMapper, CustomerVisit> implements ICustomerVisitService {
@Autowired
private ISysUserService userService;
    /**
     * 查询拜访信息列表
     *
     * @param customerVisit 拜访信息
     * @return 拜访信息
     */
    @Override
    public List<CustomerVisit> selectCustomerVisitList(CustomerVisit customerVisit) {
        List<CustomerVisit> customerVisits = getBaseMapper().selectCustomerVisitList(customerVisit);
        for (CustomerVisit visit : customerVisits) {
            SysUser sysUser = userService.selectUserById(visit.getInputUser());
            visit.setInputUserName(sysUser.getNickName());
        }
        return customerVisits;
    }

    @Override
    public boolean save(CustomerVisit entity) {
        LoginUser user = SecurityUtils.getLoginUser();
        entity.setInputUser(user.getUserId());
        entity.setInputTime(new Date());
        return super.save(entity);
    }
}
